package org.gap.dao;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.gap.domain.TiersModif;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage TiersModif entities.
 * 
 */
@Repository("TiersModifDAO")
@Transactional
public class TiersModifDAOImpl extends AbstractJpaDao<TiersModif> implements
		TiersModifDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { TiersModif.class }));

	/**
	 * EntityManager injected by Spring for persistence unit 
	 *
	 */
	@PersistenceContext(unitName = "")
	private EntityManager entityManager;

	/**
	 * Instantiates a new TiersModifDAOImpl
	 *
	 */
	public TiersModifDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findTiersModifByTmoNomChampModif
	 *
	 */
	@Transactional
	public Set<TiersModif> findTiersModifByTmoNomChampModif(String tmoNomChampModif) throws DataAccessException {

		return findTiersModifByTmoNomChampModif(tmoNomChampModif, -1, -1);
	}

	/**
	 * JPQL Query - findTiersModifByTmoNomChampModif
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<TiersModif> findTiersModifByTmoNomChampModif(String tmoNomChampModif, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersModifByTmoNomChampModif", startResult, maxRows, tmoNomChampModif);
		return new LinkedHashSet<TiersModif>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersModifByTmoDateModificationBefore
	 *
	 */
	@Transactional
	public Set<TiersModif> findTiersModifByTmoDateModificationBefore(java.util.Calendar tmoDateModification) throws DataAccessException {

		return findTiersModifByTmoDateModificationBefore(tmoDateModification, -1, -1);
	}

	/**
	 * JPQL Query - findTiersModifByTmoDateModificationBefore
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<TiersModif> findTiersModifByTmoDateModificationBefore(java.util.Calendar tmoDateModification, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersModifByTmoDateModificationBefore", startResult, maxRows, tmoDateModification);
		return new LinkedHashSet<TiersModif>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersModifByTmoDateModification
	 *
	 */
	@Transactional
	public Set<TiersModif> findTiersModifByTmoDateModification(java.util.Calendar tmoDateModification) throws DataAccessException {

		return findTiersModifByTmoDateModification(tmoDateModification, -1, -1);
	}

	/**
	 * JPQL Query - findTiersModifByTmoDateModification
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<TiersModif> findTiersModifByTmoDateModification(java.util.Calendar tmoDateModification, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersModifByTmoDateModification", startResult, maxRows, tmoDateModification);
		return new LinkedHashSet<TiersModif>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersModifByTmoNouvelleValContaining
	 *
	 */
	@Transactional
	public Set<TiersModif> findTiersModifByTmoNouvelleValContaining(String tmoNouvelleVal) throws DataAccessException {

		return findTiersModifByTmoNouvelleValContaining(tmoNouvelleVal, -1, -1);
	}

	/**
	 * JPQL Query - findTiersModifByTmoNouvelleValContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<TiersModif> findTiersModifByTmoNouvelleValContaining(String tmoNouvelleVal, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersModifByTmoNouvelleValContaining", startResult, maxRows, tmoNouvelleVal);
		return new LinkedHashSet<TiersModif>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersModifByTmoTiers
	 *
	 */
	@Transactional
	public Set<TiersModif> findTiersModifByTmoTiers(Integer tmoTiers) throws DataAccessException {

		return findTiersModifByTmoTiers(tmoTiers, -1, -1);
	}

	/**
	 * JPQL Query - findTiersModifByTmoTiers
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<TiersModif> findTiersModifByTmoTiers(Integer tmoTiers, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersModifByTmoTiers", startResult, maxRows, tmoTiers);
		return new LinkedHashSet<TiersModif>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersModifByTmoDateModificationAfter
	 *
	 */
	@Transactional
	public Set<TiersModif> findTiersModifByTmoDateModificationAfter(java.util.Calendar tmoDateModification) throws DataAccessException {

		return findTiersModifByTmoDateModificationAfter(tmoDateModification, -1, -1);
	}

	/**
	 * JPQL Query - findTiersModifByTmoDateModificationAfter
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<TiersModif> findTiersModifByTmoDateModificationAfter(java.util.Calendar tmoDateModification, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersModifByTmoDateModificationAfter", startResult, maxRows, tmoDateModification);
		return new LinkedHashSet<TiersModif>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersModifByTmoNouvelleVal
	 *
	 */
	@Transactional
	public Set<TiersModif> findTiersModifByTmoNouvelleVal(String tmoNouvelleVal) throws DataAccessException {

		return findTiersModifByTmoNouvelleVal(tmoNouvelleVal, -1, -1);
	}

	/**
	 * JPQL Query - findTiersModifByTmoNouvelleVal
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<TiersModif> findTiersModifByTmoNouvelleVal(String tmoNouvelleVal, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersModifByTmoNouvelleVal", startResult, maxRows, tmoNouvelleVal);
		return new LinkedHashSet<TiersModif>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersModifByTmoAncienneValContaining
	 *
	 */
	@Transactional
	public Set<TiersModif> findTiersModifByTmoAncienneValContaining(String tmoAncienneVal) throws DataAccessException {

		return findTiersModifByTmoAncienneValContaining(tmoAncienneVal, -1, -1);
	}

	/**
	 * JPQL Query - findTiersModifByTmoAncienneValContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<TiersModif> findTiersModifByTmoAncienneValContaining(String tmoAncienneVal, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersModifByTmoAncienneValContaining", startResult, maxRows, tmoAncienneVal);
		return new LinkedHashSet<TiersModif>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersModifByPrimaryKey
	 *
	 */
	@Transactional
	public TiersModif findTiersModifByPrimaryKey(Integer tmoTiers, String tmoNomChampModif, java.util.Calendar tmoDateModification) throws DataAccessException {

		return findTiersModifByPrimaryKey(tmoTiers, tmoNomChampModif, tmoDateModification, -1, -1);
	}

	/**
	 * JPQL Query - findTiersModifByPrimaryKey
	 *
	 */

	@Transactional
	public TiersModif findTiersModifByPrimaryKey(Integer tmoTiers, String tmoNomChampModif, java.util.Calendar tmoDateModification, int startResult, int maxRows) throws DataAccessException {
		try {
			return executeQueryByNameSingleResult("findTiersModifByPrimaryKey", tmoTiers, tmoNomChampModif, tmoDateModification);
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findTiersModifByTmoAncienneVal
	 *
	 */
	@Transactional
	public Set<TiersModif> findTiersModifByTmoAncienneVal(String tmoAncienneVal) throws DataAccessException {

		return findTiersModifByTmoAncienneVal(tmoAncienneVal, -1, -1);
	}

	/**
	 * JPQL Query - findTiersModifByTmoAncienneVal
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<TiersModif> findTiersModifByTmoAncienneVal(String tmoAncienneVal, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersModifByTmoAncienneVal", startResult, maxRows, tmoAncienneVal);
		return new LinkedHashSet<TiersModif>(query.getResultList());
	}

	/**
	 * JPQL Query - findTiersModifByTmoNomChampModifContaining
	 *
	 */
	@Transactional
	public Set<TiersModif> findTiersModifByTmoNomChampModifContaining(String tmoNomChampModif) throws DataAccessException {

		return findTiersModifByTmoNomChampModifContaining(tmoNomChampModif, -1, -1);
	}

	/**
	 * JPQL Query - findTiersModifByTmoNomChampModifContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<TiersModif> findTiersModifByTmoNomChampModifContaining(String tmoNomChampModif, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTiersModifByTmoNomChampModifContaining", startResult, maxRows, tmoNomChampModif);
		return new LinkedHashSet<TiersModif>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllTiersModifs
	 *
	 */
	@Transactional
	public Set<TiersModif> findAllTiersModifs() throws DataAccessException {

		return findAllTiersModifs(-1, -1);
	}

	/**
	 * JPQL Query - findAllTiersModifs
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<TiersModif> findAllTiersModifs(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllTiersModifs", startResult, maxRows);
		return new LinkedHashSet<TiersModif>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(TiersModif entity) {
		return true;
	}
}
